package com.minghe



import jakarta.persistence.*
import java.math.BigDecimal
import java.time.Instant
import java.time.OffsetDateTime


@Entity
@Table(name = "init_stock")
@SqlResultSetMapping(
    name = "StockSumDTOMapping",
    classes = [
        ConstructorResult(
            targetClass = StockSumDTO::class,
            columns = [
                ColumnResult(name = "stock_date", type = Instant::class),
                ColumnResult(name = "store_code", type = Int::class),
                ColumnResult(name = "product_code", type = String::class),
                ColumnResult(name = "quantity", type = BigDecimal::class)

            ]
        )
    ]
)
data class Init_Stock(

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long? = null, // 自增主键允许为 null（插入时自动生成）

    @Column(name = "stock_date", nullable = false)
    var stockDate: Instant = Instant.now(), // 默认当前时间

    @Column(name = "store_code", nullable = false)
    var storeCode: Int = 0, // 数值默认 0

    @Column(name = "product_code", nullable = false, length = 13)
    var productCode: String = "", // 空字符串默认值

    @Column(nullable = false, precision = 19, scale = 4)
    var quantity: BigDecimal = BigDecimal.ZERO, // 数值默认 0

    @Column(name = "operation_time", nullable = false)
    var operationTime: OffsetDateTime = OffsetDateTime.now(), // 默认当前时间（带时区）

    @Column(name = "transfer_time", nullable = false)
    var transferTime: OffsetDateTime = OffsetDateTime.now(),

    @Column(name = "registered_at", nullable = false)
    var registeredAt: OffsetDateTime = OffsetDateTime.now(),

    @Column(name = "registered_by", nullable = false, length = 20)
    var registeredBy: String = "system" // 默认操作者



) {
    override fun toString(): String {
        return "Init_Stock(id=$id, stockDate=$stockDate, storeCode=$storeCode, productCode='$productCode', quantity=$quantity, operationTime=$operationTime, transferTime=$transferTime, registeredAt=$registeredAt, registeredBy='$registeredBy')"
    }
}